/*
 * @(#)AtnaPooledClientITCase.java
 * Date 2013-11-02
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package us.hornerscorners.lamppost.atna.client;

import javax.inject.Inject;

import com.nesscomputing.syslog4j.util.SyslogUtility;

import org.jglue.cdiunit.ActivatedAlternatives;
import org.jglue.cdiunit.AdditionalClasses;
import org.jglue.cdiunit.CdiRunner;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import us.hornerscorners.lamppost.atna.client.inject.AtnaClientProducer;

import us.hornerscorners.lamppost.atna.client.utils.AtnaUtils;

import us.hornerscorners.lamppost.ihecommon.config.AtnaConfig;
import us.hornerscorners.lamppost.ihecommon.config.AtnaProtocolType;
import us.hornerscorners.lamppost.ihecommon.config.IHEConfig;

import us.hornerscorners.lamppost.model.audit.AuditMessage;
import us.hornerscorners.lamppost.model.audit.EventIdentificationType;


/**
 * Class description
 *
 *
 * @version        v1.0, 2013-11-02
 * @author         Jim Horner
 */
@RunWith(CdiRunner.class)
@AdditionalClasses({})
@ActivatedAlternatives({ IHEConfigTestProducer.class })
public class AtnaPooledSslTcpClientITCase {

    /** Field description */
    @Inject
    private AtnaContext atnaContext;

    /** Field description */
    @Inject
    private IHEConfig config;

    /** Field description */
    private final Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * Method description
     *
     *
     * @throws Exception
     */
    @Test
    public void sendAuditMessageTest() throws Exception {

        logger.debug("sendAuditMessageTest");

        AuditMessage msg = new AuditMessage();
        EventIdentificationType event = new EventIdentificationType();

        event.setEventID(AtnaUtils.createCodedValue("11012", "DCM", "Query"));
        event.setEventActionCode("E");
        event.getEventTypeCode().add(AtnaUtils.createCodedValue("ITI-18",
                "IHE Transactions", "Registry Stored Query"));
        msg.setEventIdentification(event);

        AtnaConfig atnaConfig = this.config.getAtnaConfig();

        atnaConfig.setProtocol(AtnaProtocolType.ssltcp);

        IAtnaClient client = AtnaClientProducer.produceClient(this.atnaContext,
                                 atnaConfig);

        client.sendAuditEvent(msg);

        SyslogUtility.sleep(1000L);
    }
}
